<template>
  <view class="main">
	 <view class="part1">
	   <view class="part2">
		<view class="part2-1">
		 提交作品
		 <view class="ptxt1">{{zpzt}}</view>
		</view> 
		<view class="part2-2">
		  <view class="ptxt2">订单号:{{oinfo.ordersn}}</view>
		  <view class="ptxt3">{{zpzt1}}</view>
		  <image src="https://ppp.new.zeroitem.cn/ppp/add.png" class="pimg30" @click="uploadvideo(0)"></image>
	    </view> 
	   </view>
	   
		<view class="partvideo ap3">
		   <video :src="video_src" style="width:444rpx;height:250rpx;" objectFit="cover" class="pimg17" :poster="video_pic" v-if="video_src!=''"></video>
		   <image :src="video_pic" style="width:444rpx;height:250rpx;" class="pimg17" v-if="video_src==''"></image>
		   <view class="part2-r">
			   <view class="pm1" :class="[{'pm_cur':video_v == 1}]" @click="version(1)">◁ 版本1</view>
			   <view class="pm1" :class="[{'pm_cur':video_v == 2}]" @click="version(2)">◁ 版本2</view>
			   <view class="pm1" :class="[{'pm_cur':video_v == 3}]" @click="version(3)">◁ 版本3</view>
			   <view class="pm2" @click="uploadvideo(1)">编辑视频</view>
		   </view>
		</view> 	   
		
	   
	   
	   
	   
	   
	  <view class="part3">
		  
		 <view class="part3-1">
		    <view class="p1">友好沟通</view>
			<view class="p2">
			  <view class="star" v-for="(item,index) in score" :class="[{'scur':item<=star1}]" @click="setstar1(item)"></view>
			</view>
		 </view> 
		<view class="part3-1">
		   <view class="p1">需求合理</view>
			<view class="p2">
               <view class="star" v-for="(item,index) in score" :class="[{'scur':item<=star2}]" @click="setstar2(item)"></view>
			</view>
		</view> 
			 
		 <view class="part3-1">
		    <view class="p1">付款大方</view>
			<view class="p2">
               <view class="star" v-for="(item,index) in score" :class="[{'scur':item<=star3}]" @click="setstar3(item)"></view>
			</view>
		 </view> 			 
			 
			 
		 
	  </view>		 
	 </view>  
	 <view class="part4">
		<view class="part4-1">
		<radio value="r1" :checked="r1==1" @click="setr()"/> 匿名评价
		</view>
		<textarea class="ptxt" placeholder="请输入评价内容" v-model="pcontent"></textarea>
		<view class="btn" @click="submitcontent()" v-if="show_btn==0">确认提交</view>
	 </view>
  </view>
</template>
 <script>
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		toLogin
	} from '@/utils/login'
	
	import {
		loadingFun,
		menuJump
	} from '@/utils/tools'	
	import {
	   getOrderDetail,updatevideo,pstj
	} from '@/api/ppp'
    import {
	  uploadFileToTencentClound
	} from '@/js_sdk/COS'
   
	const app = getApp()
	export default {
		data() {
			return {
		     zpzt:"未上传",
             zpzt1:"上传视频",
			 oid:0,
			 oinfo:[],
			 video_v:1,
			 video_src:"",
			 video_pic:"",
			 r1:0,
			 star1:0,
			 star2:0,
			 star3:0,
			 pcontent:"",
			 score:[1,2,3,4,5],
			 show_btn:0
           }
		},
		onLoad(options) {
		 var oid=options.oid;
		 this.oid=oid;
		 this.getorderinfo(oid)
		},
		onShow() {

		},

		onReachBottom() {
	    
		},
		onPullDownRefresh() {

		},

	methods: {
	 async submitcontent(){
	  if(this.oinfo['persion_upload_video']!=1){
	    uni.showToast({title:'无权限操作',icon:"none"})
	    return false;
	  }
	  var version=this.oinfo['version'];
	  if(version[0]['upload']==0 && version[1]['upload']==0 && version[2]['upload']==0){
		uni.showToast({title:'请先上传作品',icon:"none"})
		return false;  
	  }
	  if(this.pcontent==''){
		uni.showToast({title:'请填写评论',icon:"none"})
		return false;   
	  }
	  if(this.star1==0 && this.star2==0 && this.star3==0){
	  	uni.showToast({title:'请点击上方给客户进行评分',icon:"none"})
	  	return false;   
	  }
	  const{code,msg,data
	  }= await pstj({oid:this.oid,r1:this.r1,star1:this.star1,star2:this.star2,star3:this.star3,pcontent:this.pcontent});
	  if(data.suc==1){
		uni.navigateTo({
		 url:"/pages/ppp/ps/order1?oid="+this.oid	
		})  
	  }else{
		uni.showToast({title:data.msg,icon:"none"})
		return false;     
	  }
	 },
	  setstar1(score){this.star1=score;},
	  setstar2(score){this.star2=score;},
	  setstar3(score){this.star3=score;},
	  setr(){
		var r1=this.r1;
		if(r1==0){this.r1=1;return false;}
		if(r1==1){this.r1=0;return false;}
	  },
	  async getorderinfo(oid){
		const{
		code,
		msg,
		data
		}= await getOrderDetail(oid);
		this.oinfo=data;  
		 var version=data['version'];
		 this.video_src=version[0]['video_src'];
		 this.video_pic=version[0]['video_pic'];
		 this.show_btn=data.pjflag;
		 if(data.pjflag==1){
			this.pcontent=data.pjinfo.content;
		    this.star1=data.pjinfo.star1;
			this.star2=data.pjinfo.star2;
		    this.star2=data.pjinfo.star3;
		 }
		 if(version[0]['upload']==1){
		  	this.zpzt='已上传'; this.zpzt1='补充上传';
		 }
	  },
      version(type){
		this.video_v=type;
		var version=this.oinfo['version'];
		if(type==1){
		 this.video_src=version[0]['video_src'];
		 this.video_pic=version[0]['video_pic'];	
		}
		if(type==2){
		 this.video_src=version[1]['video_src'];
		 this.video_pic=version[1]['video_pic'];
		}
		if(type==3){
		 this.video_src=version[2]['video_src'];
		 this.video_pic=version[2]['video_pic'];
		}
	  },
      async updateversion(vsrc,vsrc1,upload_v){
		if(this.oinfo['persion_upload_video']!=1){
		  uni.showToast({title:'无权限上传视频',icon:"none"})
		  return false;
		}  
		const{
		code,
		msg,
		data
		}= await updatevideo({vsrc:vsrc,vsrc1:vsrc1,upload_v:upload_v,oid:this.oid});
		this.oinfo['version']=data;
		this.version(upload_v);
		uni.hideLoading();
	  },
      uploadvideo(flag){
		if(this.oinfo['persion_upload_video']!=1){
		  uni.showToast({title:'无权限上传视频',icon:"none"})
		  return false;
		}
		 var version=this.oinfo['version'];
		 var upload_v=0;
		 if(flag==0){
		  if(version[0]['upload']==0){upload_v=1;}
		  else if(version[1]['upload']==0){upload_v=2;} 
		  else if(version[2]['upload']==0){upload_v=3;} 
		  if(upload_v==0){
			uni.showToast({
				title:'最多只能上传3个版本视频了,您可以下方编辑版本视频',
				icon:"none"
			})
			return false;  
		  }
		 }
		 if(flag==1){upload_v=this.video_v;}
		 var that=this;
			uni.chooseMedia({
				count:1,
				mediaType:['video'],
				sourceType: ['camera', 'album'],
				success: function (res) {
				  let filePath =res.tempFiles[0].tempFilePath;
				  let ext = filePath.substr(filePath.lastIndexOf('.') + 1);
				  var timestamp = (new Date()).valueOf();
				  var filename=timestamp+"."+ext;
				  
				  let filePath1 =res.tempFiles[0].thumbTempFilePath;
				  let ext1 = filePath1.substr(filePath1.lastIndexOf('.') + 1);
				  var filename1=timestamp+"."+ext1;
				  uni.showLoading({title:"视频上传中",mask:true});
				  uploadFileToTencentClound(filename,filePath).then((res1)=>{
				  	
					//that.vname=filename;
					//that.vsrc='https://ppp-1300934138.cos.ap-shanghai.myqcloud.com/wxFile/'+filename;
				    var vsrc='https://ppp-1300934138.cos.ap-shanghai.myqcloud.com/wxFile/'+filename;
					uploadFileToTencentClound(filename1,filePath1).then((res1)=>{
				        that.zpzt="已上传";
						that.zpzt1="补充上传";
					    var vsrc1='https://ppp-1300934138.cos.ap-shanghai.myqcloud.com/wxFile/'+filename1; 
						that.updateversion(vsrc,vsrc1,upload_v);	
					})			
				  })
			
		
				 }
		    });  
		  },		  
		  
		  
		  
		  
		},
		computed: {
			...mapGetters(['isLogin']),
		}
	}
</script>

<style>
 @import "./tjzp.css";	
</style>
